<?php

class ServiceBase {

	// 获取用户空间
	function getUserSpace($uId) {
		global $_SGLOBAL;
		$uId = intval($uId);
		$query = $_SGLOBAL['db']->query("SELECT sf.*, s.* FROM ".tname('space')." s
										LEFT JOIN ".tname('spacefield')." sf ON sf.uid=s.uid
										WHERE s.uid='$uId'");
		$space = $_SGLOBAL['db']->fetch_array($query);
		return $space;
	}

	function _space2user($space) {
		global $_SC, $_SGLOBAL;
		$founders = explode(',', $_SC['founder']);
		$adminLevel = 'none';
		if (in_array($space['uid'], $founders)) {
			$adminLevel = 'founder';
		} else {
			@include_once S_ROOT . './data/data_usergroup.php';
			if(!empty($_SGLOBAL['usergroup'][$space['groupid']]['manageconfig'])) {
				$adminLevel = 'manager';
			}
		}
		$privacy = unserialize($space['privacy']);
		$debug[] = $space['privacy'];
		$debug[] = $privacy;

		$user = array(
			'uId'		=> $space['uid'],
			'handle'	=> $space['username'],
			'action'	=> $space['action'],
			'realName'	=> $space['name'],
			'realNameChecked' => $space['namestatus'] ? true : false,
			'spaceName'	=> $space['spacename'],
			'gender'	=> $space['sex'] == 1 ? 'male' : ($space['sex'] == 2 ? 'female' : 'unknown'),
			'email'		=> $space['email'],
			'qq'		=> $space['qq'],
			'msn'		=> $space['msn'],
			'birthday'	=> sprintf('%04d-%02d-%02d', $space['birthyear'], $space['birthmonth'], $space['birthday']),
			'bloodType'	=> empty($space['blood']) ? 'unknown' : $space['blood'],
			'relationshipStatus' => $space['marry'] == 1 ? 'single' : ($space['marry'] == 2 ? 'notSingle' : 'unknown'),
			'birthProvince' => $space['birthprovince'],
			'birthCity'	=> $space['birthcity'],
			'resideProvince' => $space['resideprovince'],
			'resideCity'	=> $space['residecity'],
			'viewNum'	=> $space['viewnum'],
			'friendNum'	=> $space['friendnum'],
			'myStatus'	=> $space['note'],
			'lastActivity' => $space['updatetime'],
			'created'	=> $space['dateline'],
			'credit'	=> $space['credit'],
			'isUploadAvatar'	=> $space['avatar'] ? true : false,
			'adminLevel'		=> $adminLevel,
			'homepagePrivacy'	=> $privacy['view']['index'] == 1 ? 'friends' : ($privacy['view']['index'] == 2 ? 'me' : 'public'),
			'profilePrivacy'	=> $privacy['view']['profile'] == 1 ? 'friends' : ($privacy['view']['profile'] == 2 ? 'me' : 'public'),
			'friendListPrivacy'	=> $privacy['view']['friend'] == 1 ? 'friends' : ($privacy['view']['friend'] == 2 ? 'me' : 'public')
		);

		return $user;
	}
}